package com.hutao.chargingpile.pitfall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hutao.chargingpile.pitfall.mapper.CpHitchManagerMapper;
import com.hutao.chargingpile.pitfall.pojo.dto.ExcelCpHitchDTO;
import com.hutao.chargingpile.pitfall.pojo.entity.CpHitch;
import com.hutao.chargingpile.pitfall.service.CpHitchManagerService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class CpHitchManagerServiceImpl extends ServiceImpl<CpHitchManagerMapper, CpHitch> implements CpHitchManagerService {

    @Resource
    private CpHitchManagerMapper cpHitchManagerMapper;


    /**
     * 查询所有故障信息
     *
     * @return
     */
    @Override
    public List<CpHitch> findAllHitch(Map<String, Object> map) {
        return cpHitchManagerMapper.findAllHitch(map);
    }

    /**
     * 查询总条数
     *
     * @return
     */
    @Override
    public int findCount(Map<String, Object> map) {
        return cpHitchManagerMapper.findCount(map);
    }

    /**
     * Excel导出
     * @return
     */
    @Override
    public List listCpHitchData() {
        List<CpHitch> cpHitchList = cpHitchManagerMapper.excelCpHitchDTO();
        //创建ExcelDicDTO列表，将Dict列表转换成ExcelDictDTO列表
        ArrayList<ExcelCpHitchDTO> excelDictDTOList = new ArrayList<>(cpHitchList.size());
        cpHitchList.forEach(cpHitch -> {
            ExcelCpHitchDTO excelCpHitchDTO = new ExcelCpHitchDTO();
            BeanUtils.copyProperties(cpHitch , excelCpHitchDTO);
            excelDictDTOList.add(excelCpHitchDTO);
        });
        return excelDictDTOList;
    }

    /**
     * 批量逻辑删除
     *
     * @return
     */
    @Override
    public int removeIds(List ids) {
        return cpHitchManagerMapper.removeIds(ids);
    }

    /**
     * 新增故障信息
     * @param cpHitch
     * @return
     */
    @Override
    public int addCpHitchManager(CpHitch cpHitch) {
        return cpHitchManagerMapper.addCpHitchManager(cpHitch);
    }
}
